package com.fengye.redisson.demo.message;

import com.fengye.redisson.demo.dto.MessageDTO;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *
 * @author sky
 * @date 2021年06月16日 10:34 上午
 */
@Component
@Slf4j
public class MsgPublisher {

    @Autowired
    private RedissonClient redissonClient;


    static final String topicName = "REDISSON_TOPIC";
    public void sendMsg(MessageDTO dto) {
        try {
            RTopic topic = redissonClient.getTopic(topicName);
            topic.publish(dto);
            log.info("消息成功发送,{}", dto);
        }catch (Exception e){
            log.error("发送消息失败");
        }
    }
}
